#include <exiv2/exiv2.hpp>
#include <iostream>
#include <iomanip>
#include <cassert>

using namespace std;
int main3()
{
    std::string file("/home/xiaoguo/Codes/c++practics/gps/mmm.jpg");
    Exiv2::ExifData exifData;

    std::cout << "Added a few tags the quick way.\n";
    // Create a ASCII string value (note the use of create)
    Exiv2::Value::AutoPtr v = Exiv2::Value::create(Exiv2::asciiString);
    // Set the value to a string
    v->read("1999:12:31 23:59:59");

    // Add the value together with its key to the Exif data container
    Exiv2::ExifKey key("Exif.Photo.DateTimeOriginal");
    exifData.add(key, v.get());

    std::cout << "Added key \"" << key << "\", value \"" << *v << "\"\n";

    // *************************************************************************
    // Modify Exif data
    // Since we know that the metadatum exists (or we don't mind creating a new
    // tag if it doesn't), we can simply do this:
    Exiv2::Exifdatum& tag = exifData["Exif.Photo.DateTimeOriginal"];
    std::cout<<"tag is "<<tag<<std::endl;
    std::string date = tag.toString();
    std::cout<<"Exif.Photo.DateTimeOriginal is "<<date<<std::endl;
    date.replace(0, 4, "2001");
    tag.setValue(date);
    std::cout << "Modified key \"" << tag.key()
              << "\", new value \"" << tag.value() << "\"\n";

    Exiv2::Exifdatum& time_tag = exifData["Exif.Photo.DateTimeOriginal"];
    std::string time_date = time_tag.toString();
    std::cout<<"Exif.Photo.DateTimeOriginal is "<<time_date<<std::endl;

    // *************************************************************************
    // Finally, write the remaining Exif data to the image file
    Exiv2::Image::AutoPtr image = Exiv2::ImageFactory::open(file);
    assert(image.get() != 0);
    image->setExifData(exifData);
    image->writeMetadata();
    return 0;
}
